#ifndef DECODER_H_
#define DECODER_H_

#include <map>
#include <vector>

using namespace std;

/* the strictly smaller comparison for vector<bool> */
class comp {
public:
	bool operator () (const vector<bool>& k1, 
					  const vector<bool>& k2) {
		for (int i=0; i<min(k1.size(), k2.size()); i++) {
			if (k1[i] != k2[i] && k1[i]==false)
				return true;
			else if (k1[i] != k2[i] && k1[i]==true)
				return false;
		}
	}
};

typedef map<vector<bool>, char, comp> LUT;
struct BaseCol {
	int L;
	vector<bool> F;
	LUT* O;
	vector<vector<bool> > indexO;
	BaseCol(): L(0), O(0) {}
};

/* decoder class */
class Decoder {
public:
	void decode(const char*);
	Decoder(const char*);
	int lmbc (const vector<bool>&, int);
	vector<bool> fkb(const vector<bool>&, int, int);
	void getSymbol(const vector<bool>&, int);

private:
	vector<LUT> oleft;
	vector<LUT> oright;
	vector<BaseCol> lBase;
	vector<BaseCol> rBase;
};

#endif
